
var ajaxUrl = require('../../utils/url.js');
var app = getApp()
Page({
  data: {
    imgUrls: [
           
        ],
        indicatorDots: true,
        autoplay: true,
        interval: 3000,
        duration: 1000,
        page:0,
        goodid:"",
        postsList:{},
        response:"",
        hidden:false
  },
  
  onLoad: function (options) {
    var that = this;
    console.log("goodid:"+options.goodid);
    //ajax请求数据
    that.setData({
      goodid:options.goodid
    });
    that.fetchInfoDate();
   // console.log(that.data.postsList)
  },
  
 
  fetchInfoDate:function(data){
    var self = this;
    self.setData({
      hidden: false
    });
   
      if (!data) data = {};
      if (!data.page) data.page = 0;
      if (data.page === 0) {
        self.setData({
          postsList: {}
        });
      }
      console.log(ajaxUrl.ajaxUrl()+"item/"+self.data.goodid);
      wx.request({
          method:"GET",
          url:ajaxUrl.ajaxUrl()+"item/"+self.data.goodid,
          data:{},
          header: {
          'Authorization': ajaxUrl.getCiphertext()
          },
          success: function(res) {
            console.log("detail:"+res.data)
             // var contentObj = [];
               if(res.data.code == 0){               
                  {
                    var desct = res.data.data.descriptions; 
                    var descarr = desct.split("img");
                    var descArray = [];
                    for(var i=0;i<descarr.length;i++)
                    {
                      var temparr = descarr[i].match(/src=\"(\S*)\"/);
                      if(temparr)
                      {  
                        descArray.push(temparr[1]);                        
                      }
                    }
                    self.setData({
                      postsList: {imgUrl:res.data.data.mainImage,
                        desc:desct,
                        descArr:descArray,
                        advPrice:res.data.data.inventories[0].adviceSalePrice,
                        oriPrice:res.data.data.inventories[0].originalPrice,
                        name:res.data.data.name,
                        content:res.data.data.extra
                      }
                    });
                  }
               }
               
              //   self.data.postsList = contentObj
               setTimeout(function () {
                  self.setData({
                    hidden: true
                  });
              }, 300);
          }
      })
      
  },
  onShareAppMessage: function () {
    return {
      title: '恒泰云跨境购',
      desc: '商品列表',
      path: '/pages/goods/detail?goodid='+this.data.goodid
    };
  }
 
})
